﻿function SetUploadify( ctrl, callbackFunctionName )
{
    if(!callbackFunctionName)
    {
        callbackFunctionName = "cutCallback";
    }

    $(ctrl).uploadify({
        height: 30,
        swf: 'js/uploadify/uploadify.swf',
        uploader: '/server/DraftUpload.ashx',
        buttonImage: '/images/SubmitInfo/upload.png',
        queueSizeLimit: 1,
        multi: false,
        fileSizeLimit: '500KB',
        fileTypeDesc: "Picture",
        fileTypeExts: "*.jpeg;*.jpg;*.png;*.gif;",
        width: 90,
        removeTimeout:0,
        'onUploadSuccess': function (file, data, response)
        {
            // alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
            if( $("body").find("#upload_colorbox").length == 0  )
            {
                var ctrl =$("<a id='upload_colorbox' style='display:none' title='裁剪图片' class='iframe'>hidden uploader</a>");
                $("body").append(ctrl);
            }
            var ctrl = $("#upload_colorbox");
            ctrl.attr("href", "/CutImg.aspx?cutWidth=300&cutHeight=300&src=" + encodeURI( data ) + "&callback=" + callbackFunctionName );
                    
            ctrl.colorbox({iframe:true, width:"800", height:"600",close :"关闭",overlayClose:false});
            ctrl.click();
        },
        'onUploadError': function (file, errorCode, errorMsg, errorString)
        {
            alert("上传失败:" + errorString);
        },
        'onSelectError':function(file, errorCode, errorMsg)
        {
            switch(errorCode) 
            {
                case -100:
                    alert("上传的文件数量已经超出系统限制的"+$('#file_upload').uploadify('settings','queueSizeLimit')+"个文件！");
                    break;
                case -110:
                    alert("文件 ["+file.name+"] 大小超出系统限制的500K大小！");
                    break;
                case -120:
                    alert("文件 ["+file.name+"] 大小异常！");
                    break;
                case -130:
                    alert("文件 ["+file.name+"] 类型不正确！");
                    break;

            }
        }
    });
}

function SetUploadifyForTeamHead( ctrl, callbackFunctionName )
{
    if(!callbackFunctionName)
    {
        callbackFunctionName = "cutCallback";
    }

    $(ctrl).uploadify({
        height: 62,
        swf: 'js/uploadify/uploadify.swf',
        uploader: '/server/DraftUpload.ashx',
        buttonImage: '/images/BabyGroup/selectpic.png',
        queueSizeLimit: 1,
        multi: false,
        fileSizeLimit: '500KB',
        fileTypeDesc: "Picture",
        fileTypeExts: "*.jpeg;*.jpg;*.png;*.gif;",
        width: 215,
        removeTimeout:0,
        'onUploadSuccess': function (file, data, response)
        {
            // alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
            if( $("body").find("#upload_colorbox").length == 0  )
            {
                var ctrl =$("<a id='upload_colorbox' style='display:none' title='您现在上传的合影将成为你们的共同头像，上传成功之后不能不能撤回喔' class='iframe'>hidden uploader</a>");
                $("body").append(ctrl);
            }
            var ctrl = $("#upload_colorbox");
            ctrl.attr("href", "/CutImg.aspx?type=team&cutWidth=606&cutHeight=300&src=" + encodeURI( data ) + "&callback=" + callbackFunctionName );
                    
            ctrl.colorbox({iframe:true, width:"1000", height:"700",close :"关闭",overlayClose:false});
            ctrl.click();
        },
        'onUploadError': function (file, errorCode, errorMsg, errorString)
        {
            alert("上传失败:" + errorString);
        },
        'onSelectError':function(file, errorCode, errorMsg)
        {
            switch(errorCode) 
            {
                case -100:
                    alert("上传的文件数量已经超出系统限制的"+$('#file_upload').uploadify('settings','queueSizeLimit')+"个文件！");
                    break;
                case -110:
                    alert("文件 ["+file.name+"] 大小超出系统限制的500K大小！");
                    break;
                case -120:
                    alert("文件 ["+file.name+"] 大小异常！");
                    break;
                case -130:
                    alert("文件 ["+file.name+"] 类型不正确！");
                    break;

            }
        }
    });
}

function setUploadImageResult( imgCtrl, hdInput, url)
{
    if( !url || url == "" )
    {
        $(imgCtrl).removeClass("uploadimagehidden uploadimageshow").addClass("uploadimagehidden");
        $(imgCtrl).attr("src","");
        $(hdInput).val("")
    }
    else
    {
        $(imgCtrl).removeClass("uploadimagehidden uploadimageshow").addClass("uploadimageshow");
        $(imgCtrl).attr("src",url);
        $(hdInput).val(url)
    }
}